package com.smart.order.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;

import java.time.LocalDateTime;

public class OrderUtils {
    private static final String DATE_FORMAT = "yyyyMMdd";

    //  自增
    public static String createOrderSn(Long uid, Integer sourceType) {
        // 8位 日期   + 用户ID  + 2位 来源   +  6位随机数
        return String.format("%s%s%s%s",
                DateUtil.format(LocalDateTime.now(), DATE_FORMAT),
                uid,
                sourceType,
                RandomUtil.randomNumbers(6)
        );
    }

    public static void main(String[] args) {
        String orderSn = createOrderSn(1000L, 10);
        System.out.println(orderSn);
    }


}
